package com.cpecc.dao.system;

import javax.annotation.Resource;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;
import com.cpecc.model.system.Sign;
import com.cpecc.model.system.User;

@Repository
public class SignDao {
	
	@Resource
	private SessionFactory sessionFactory;
	
	public void save(Sign sign){
		Session session=sessionFactory.getCurrentSession();
		session.save(sign);
		session.flush();
	}
	
	public Sign get(User user){
		String hql="from Sign t where t.user=?";
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		query.setParameter(0, user);
		if(query.list().size()>0)
			return 	(Sign) query.list().get(0);
		else
			return null;
	}
}
